<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
	<title>函数去除重复代码</title>
</head>
<body>
     
</body>
<script type="text/javascript">
	// 计算电影票折扣10%，15%，20%，
	matineeTicket = adultTicket * (1 - 0.10);
	seniorTicket = adultTicket * (1 - 0.10);
	childTicket = adultTicket * (1 - 0.10);
	// 三段类似的代码整合
	function discountPrice(price,percentage) {
		return (price * (1 - (percentage / 100)) );
	}
	matineeTicket = discountPrice(adultTicket , 10);
	seniorTicket = discountPrice(adultTicket , 15);
	childTicket = discountPrice(adultTicket , 20);
</script>
</html>